package com.yujistu.utils;

import android.util.Log;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * Created by S3YOGA on 2015/11/3.
 */
public class Logger {

    public static int MAX_MESSAGE_SIZE = Integer.MAX_VALUE; // MUST < 2048

    private static boolean isDebug = true;//是否允许输出log

    private static boolean saveLogToSD = true;

    private static String TAG = "YuJiYoga";


    public static void v(String s) {


    }

    public static void d(String msg) {
        String className = TAG;
        int line = (new Throwable()).getStackTrace()[1].getLineNumber();
        String method = (new Throwable()).getStackTrace()[1].getMethodName();
        if(null != msg){
           if(isDebug){
               Log.d(className, (new Throwable()).getStackTrace()[1].getClassName() + " @Line" + line + ":" + method + "() " + msg);
           }
        }else{
             Log.e(Logger.class.getName(), "Invalid parameters: " + className + ", " + msg);
        }
    }

    public static void i(String s) {


    }

    public static void w(String s) {


    }

    public static void e(String s) {


    }

    public static void ex(Throwable e) {
        String className = (new Throwable()).getStackTrace()[1].getMethodName();
        if(null != e){
            StringWriter sw = new StringWriter();
            PrintWriter  pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            e.printStackTrace();
            String s = sw.toString();

            int line = (new Throwable()).getStackTrace()[1].getLineNumber();
            String method = (new Throwable()).getStackTrace()[1].getMethodName();
            if(isDebug){
                Log.e(className, " @Line" + line + ":" + method + "() " + s);
            }

        }else{
            Log.e(Logger.class.getName(), "Invalid parameters: " + className + ", " + e);
        }
    }
}
